/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.tces.view;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.tces.controller.CategoryDAO;
import com.tces.controller.ChoiceDAO;
import com.tces.controller.QuestionDAO;
import com.tces.model.Categories;
import com.tces.model.Choices;
import com.tces.model.Questions;
import com.tces.model.Students;
import java.util.List;
import org.apache.log4j.Logger;

/**
 *
 * @author arnolda
 */
public class CategoryAction extends ActionSupport {

    private static final Logger log = Logger.getLogger(CategoryAction.class);
    private List<Categories> categoryList;
    private Students student;
    private String dataContent,subjectScheduleID;

    public String view() {
        try {
            log.info("Praise God");
            dataContent = "<input type=\"hidden\" name=\"subjectScheduleID\" id=\"subjectScheduleID\" value=\""+subjectScheduleID+"\" />";
            student = (Students) ActionContext.getContext().getSession().get("student");
            System.out.println("Student :" + student.getStudentIDNumber());
            categoryList = CategoryDAO.getActiveCategories();
            for (Categories category : categoryList) {
                dataContent += "<div class=\"art-post-inner art-article\">"
                        + "<h2 class=\"art-postheader tce-green-bg tce-white-font tce-clear-margin tce-padding\">";
                dataContent += category.getCategoryName();
                dataContent += "</h2>"
                        + "<div class=\"art-postcontent tce-margin\">"
                        + "<ol>";
                List<Questions> questionList = QuestionDAO.getActiveQuestions(category.getCategoryID());
                for (Questions question : questionList) {
                    dataContent += "<li>" + question.getQuestionDescription();
                    List<Choices> choiceList = ChoiceDAO.getActiveChoices(question.getQuestionID());
                    if(choiceList.size() > 0){
                        dataContent+="<ul class=\"tce-medium-padding\">";
                        for(Choices choice: choiceList){
                            String optionName="c"+category.getCategoryID()+"q"+question.getQuestionID();
                            dataContent+="<li class=\"\"><input type=\"radio\" id=\""+optionName+"ch"+choice.getChoiceID()+"\" name=\""+optionName+"\" value=\""+choice.getChoiceID()+"\" class=\"tce-margin validate[required] radio\" /><span class=\"tce-margin\">"+choice.getChoiceValue()+"</span></li>";
                        }
                        dataContent +="</ul>";
                    }
                     dataContent +="</li>";
                }
                dataContent += "</ol>"
                        + "</div>"
                        + "<div class=\"cleared\"></div>"
                        + "</div>";
            }
        } catch (Exception ex) {
            log.error(ex);

        }
        return SUCCESS;
    }

    public String getSubjectScheduleID() {
        return subjectScheduleID;
    }

    public void setSubjectScheduleID(String subjectScheduleID) {
        this.subjectScheduleID = subjectScheduleID;
    }

    public List<Categories> getCategoryList() {
        return categoryList;
    }

    public void setCategoryList(List<Categories> categoryList) {
        this.categoryList = categoryList;
    }

    public String getDataContent() {
        return dataContent;
    }

    public void setDataContent(String dataContent) {
        this.dataContent = dataContent;
    }
    
}
